package com.cooba.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.bean.NewsBean;
import com.cooba.pullTorefresh.PullToRefreshListView;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

/**
 * Created by Administrator on 2015/12/21.
 * 新闻
 */
public class MyAdapter extends BaseAdapter {

    private Context context;
    private List<NewsBean> lists;
    private PullToRefreshListView rListView;
    public List<NewsBean> getLists() {
        return lists;
    }

    public void setLists(List<NewsBean> lists) {
        this.lists = lists;
        notifyDataSetChanged();
    }

    public MyAdapter(Context context, List<NewsBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    public MyAdapter(Context context, List<NewsBean> lists, PullToRefreshListView rListView) {
        this.context = context;
        this.lists = lists;
        this.rListView = rListView;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.news_list_item, parent, false);
            //   convertView = LayoutInflater.from(context).inflate(R.layout.news_list_item, null);
            holder.title = (TextView) convertView.findViewById(R.id.tv1);
            holder.description = (TextView) convertView.findViewById(R.id.tv2);
            holder.img = (ImageView) convertView.findViewById(R.id.iv);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(lists.get(position).title);//标题
        holder.description.setText(lists.get(position).description);//描述
        //图片
        BitmapUtils bitmapUtils = new BitmapUtils(context);
        String cover = lists.get(position).img_url;
        bitmapUtils.display(holder.img, cover);
        return convertView;
    }

    class ViewHolder {
        public TextView title;
        public TextView description;
        public ImageView img;

    }
    class ViewHolder2 {
        public TextView title;
        public TextView description;
        public ImageView img1,img2,img3;

    }

}
